
var EchartsModel;
define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
    EchartsModel=Echarts;
    /************************日期时间选择的插件**********************/
    //绑定select元素事件
    require(['bootstrap-datetimepicker'], function () {
        var options = {
            format: 'YYYY-MM-DD HH:mm:ss',
            icons: {
                time: 'fa fa-clock-o',
                date: 'fa fa-calendar',
                up: 'fa fa-chevron-up',
                down: 'fa fa-chevron-down',
                previous: 'fa fa-chevron-left',
                next: 'fa fa-chevron-right',
                today: 'fa fa-history',
                clear: 'fa fa-trash',
                close: 'fa fa-remove'
            },
            showTodayButton: true,
            showClose: true
        };
        $('.datetimepicker').parent().css('position', 'relative');
        $('.datetimepicker').datetimepicker(options);
    });
    /************************日期时间选择的插件**********************/
});

//切换商户获取ajax
$('#tijiao').click(function aa(){
    var starttime   = $('#starttime').val();     //开始时间
    var endtime   = $('#endtime').val();     //结束时间
    var admin   = $('#admin').val();     //责任人
    $.ajax({
        url:"/manager.php/chartoilinve/merchantAjax",
        type:"POST",
        dataType:'json',
        data : {starttime:starttime, endtime:endtime, admin:admin},
        async:false,
        success:function(e){
            if(e.code==200){
                var data = e.data;
                dataArr = data['data'];//数据
                daysArr = data['days'];//时间
                typeArr = data['type'];//类别
                var myChart = EchartsModel.init(document.getElementById('echart'));

                option = {
                    title: {
                        text: '油库库存图表'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: typeArr
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {},
                            //区域缩放，区域缩放还原
                            dataZoom  : {yAxisIndex: 'none'},
                            //数据视图
                            dataView: {
                                readOnly: false
                            },
                            //切换为折线图，切换为柱状图
                            magicType: {
                                type: ['line', 'bar']
                            },
                            restore: {},  //还原
                        }
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: daysArr
                    },
                    yAxis: {
                        type: 'value',
                        name: '单位：吨',
                    },
                    series: [
                        {
                            name: typeArr[0],
                            type: 'line',
                            stack: '总量',
                            data: dataArr['inventory']
                        },
                        {
                            name: typeArr[1],
                            type: 'line',
                            stack: '总量',
                            data: dataArr['comein']
                        },
                        {
                            name: typeArr[2],
                            type: 'line',
                            stack: '总量',
                            data: dataArr['used']
                        },
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        }
    })
})